#!/bin/bash

# DevOps管理平台停止脚本

echo "🛑 停止DevOps管理平台..."

# 停止Django ASGI服务
echo "🐍 停止Django ASGI服务..."
pkill -f "python.*manage.py.*runserver"
pkill -f "daphne.*devops_platform.asgi"

# 停止Celery Worker
echo "⚡ 停止Celery Worker..."
pkill -f "celery.*worker"

# 停止Celery Beat
echo "⏰ 停止Celery Beat..."
pkill -f "celery.*beat"

# 停止Vue.js服务
echo "🎨 停止Vue.js服务..."
pkill -f "node.*vite"

# 等待进程完全停止
sleep 2

echo ""
echo "✅ 所有服务已停止"
echo ""
echo "📋 剩余进程检查："

# 检查是否还有相关进程
if pgrep -f "python.*manage.py.*runserver\|daphne.*devops_platform.asgi" > /dev/null; then
    echo "⚠️  Django进程仍在运行"
else
    echo "✅ Django已停止"
fi

if pgrep -f "celery.*worker" > /dev/null; then
    echo "⚠️  Celery Worker进程仍在运行"
else
    echo "✅ Celery Worker已停止"
fi

if pgrep -f "celery.*beat" > /dev/null; then
    echo "⚠️  Celery Beat进程仍在运行"
else
    echo "✅ Celery Beat已停止"
fi

if pgrep -f "node.*vite" > /dev/null; then
    echo "⚠️  Vue.js进程仍在运行"
else
    echo "✅ Vue.js已停止"
fi

echo ""
echo "💡 注意: MySQL和Redis服务仍在运行"
echo "   如需停止请手动执行:"
echo "   sudo systemctl stop mysql"
echo "   sudo systemctl stop redis-server"
